package com.codetile.batch.config;

import org.springframework.batch.core.*;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

//@Configuration
//@EnableBatchProcessing
public class ParametersDemo
//        implements StepExecutionListener
{

    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    private Map<String,JobParameter> parameters;

//    @Bean
//    public Job parameterJob(){
//        return jobBuilderFactory.get("parameterJob")
//                .start(parameterStep())
//                .build();
//    }
//
//    @Bean
//    public Step parameterStep() {
//
//        return stepBuilderFactory.get("parameterStep")
//                .listener(this)
//                .tasklet(new Tasklet() {
//                    @Override
//                    public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
//                        System.out.println(parameters.get("info"));
//
//                        return RepeatStatus.FINISHED;
//                    }
//                }).build();
//    }


//    @Override
//    public void beforeStep(StepExecution stepExecution) {
//        parameters=stepExecution.getJobParameters().getParameters();
//    }
//
//    @Override
//    public ExitStatus afterStep(StepExecution stepExecution) {
//        return null;
//    }
}
